home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 029a / readm110.zip / CONIO.ASM < prev    next >
Assembly Source File  |  1990-01-31  |  13KB  |  249 lines

  1. ;
  2. ;  Name:             CONIO.ASM
  3. ;  Purpose:          keyboard & text video functions
  4. ;  Calling Language: Borland Turbo Pascal 5.50
  5. ;  Date:             December 8, 1989
  6. ;  Assembler:        Borland Turbo Assembler 1.00
  7. ;  Author:           J. Rockford Cogar
  8. ;  Company:          Nucleus Inc. 761 Emory Valley Road, Oak Ridge TN 37830
  9. ;  Rights:           You MAY use this code for ANY purpose private or commercial
  10. ;
  11.         .MODEL  TPASCAL
  12.         .CODE
  13. ; prototype: void near cursorxy(byte col, byte row);
  14.         PUBLIC cursorxy
  15. ;***********************************************************************
  16. cursorxy proc   near col: BYTE, row: BYTE
  17.          mov    ah,02                           ; set cursor position function
  18.          mov    bh,0                            ; page zero
  19.          mov    dh,row                          ; set glyph row number
  20.          mov    dl,col                          ; set glyph column number
  21.          int    010h                            ; do BIOS video interrupt call
  22.          ret
  23. cursorxy        ENDP
  24. ;***********************************************************************
  25.  
  26. ; prototype: int near cgets(char *strg);
  27. ; purpose:   emulate the Turbo C cgets() function
  28. ;            *strg is the string to input into
  29. ;
  30.         PUBLIC cgets
  31. ;***********************************************************************
  32. cgets    proc   near strg: DWORD
  33.          push   ds
  34.          lds    si,dword ptr strg;      ; load the pointer
  35.          mov    dx,si                   ; PASS ptr in DS:DX
  36.          mov    ah,10;                  ; DOS bufferd KBD input function
  37.          int    21h                     ; call DOS
  38.          mov    si,dx
  39.          inc    si                      ; point to the next (strg[1]) byte
  40.          cld
  41.          lodsb                          ; fetch strg[1]
  42.          mov    ah,0                    ; zero the hi byte
  43.          pop    ds
  44.          ret
  45. cgets    ENDP
  46. ;***********************************************************************
  47.  
  48. ;       Function Name:        getscode
  49. ;       Function Prototype:   integer getscode(void);
  50. ;       Calling Language:     Turbo Pascal 5.50
  51. ;       Purpose:              Read the current scan code
  52. ;       External Code:        None
  53. ;       Returns:              scan code in AX register, zero if no key was ready
  54. ;
  55.         PUBLIC getscode
  56. ;***********************************************************************
  57. getscode proc near
  58.         mov     ah,1
  59.         int     016h                    ; bios kbd int service
  60.         jnz     kready                  ; jmp to get the key that is ready
  61.                                         ; top of key not ready block
  62.         xor     ax,ax                   ; set AX to say no key was ready
  63.         jmp     retgsc                  ; return to calling function
  64. kready:
  65.         mov     ah,0
  66.         int     016h                    ; bios kbd int service
  67.         xchg    al,ah                   ; puts scan code in AL
  68.         mov     ah,0                    ; zero out the ascii code
  69. retgsc:
  70.         ret
  71. getscode endp
  72. ;***********************************************************************
  73.  
  74. ;       Function Name:        readkbd
  75. ;       Function Prototype:   integer readkbd(void);
  76. ;       Calling Language:     Turbo Pascal 5.50
  77. ;       Purpose:              Pause and Read the current scan code
  78. ;       External Code:        None
  79. ;       Returns:              scan code in AX register
  80. ;
  81.         PUBLIC readkbd
  82. ;***********************************************************************
  83. readkbd proc near
  84.         mov     ah,0
  85.         int     016h                    ; bios kbd int service
  86.         int     016h                    ; bios kbd int service
  87.         xchg    al,ah                   ; puts scan code in AL
  88.         mov     ah,0                    ; zero out the ascii code
  89.         ret
  90. readkbd endp
  91. ;***********************************************************************
  92.  
  93. ; integer near getvmode(void)
  94. ;  used to get the current BIOS video mode
  95. ;
  96.        PUBLIC getvmode
  97. ;***********************************************************************
  98. getvmode proc near
  99.          mov    ah,0fh                          ; BIOS service to get the current video mode
  100.          int    010h                            ; call BIOS
  101.          mov    ah,0                            ; zero out width of text mode screen
  102.          ret
  103. getvmode endp
  104. ;***********************************************************************
  105. ;
  106. ;   void near snowwrite(int col, int row, char color, char *strg, int soff, int maxchars, int clrchar);
  107. ;   col      : int      ;  CRT column
  108. ;   row      : int      ;  CRT row
  109. ;   color    : byte     ;  color to write the string in
  110. ;   strg     : *char    ;  string to write
  111. ;   soff     : int      ;  position of (array index) of first char to write
  112. ;   maxchars : int      ;  maximum number of chars to write
  113. ;   clrchar  : int      ;  number of chars to clear (field width)
  114. ; Write a string to the CRT and clear the specified nunber of spaces
  115. ; providing the string does not fill the entire field
  116. ; also start the write from sourceof and only write maxchars
  117. ; * for text modes only!
  118. ;
  119.            PUBLIC snowwrite
  120. ;***********************************************************************
  121. snowwrite   proc near col:WORD, row:WORD, color:BYTE, strg:DWORD, soff:WORD, maxchars:WORD, clrchar:WORD
  122.             LOCAL strlen:WORD, toclear:WORD=AUTO_SIZE
  123.             push    ds
  124.             cld                         ; clear direction flag
  125.             les     di,strg             ; load seg & off dor large data models
  126.             mov     al,byte ptr es:[di] ; fetch length byte
  127.             mov     ah,0                ; limit length to 255 bytes
  128.             mov     bx,word ptr soff    ; sourceof.  get the string source offset
  129.             cmp     ax,bx               ; compare str length (AX) with str offset (BX)
  130.             jg      itsok               ; jump to assignment if string offset < string length
  131.             jmp     SHORT notok         ; if string offset > string length goto notok:
  132. itsok:      sub     ax,bx               ; adjust the string length for the new offset
  133.             jmp     SHORT assgn         ; jump dowm to assgn
  134. notok:      mov     ax,0000H            ; zero out AX (string length) cause the specified string offset was too big
  135. assgn:      mov     [strlen],ax         ; store the string length in strlen (vaiable)
  136.             sub     ax,ax               ; zero out AX
  137.             mov     es,ax               ; put zero in for extra segment
  138.             mov     al,es:[0449h]       ; offset of 449h is needed
  139.             cmp     al,7                ; is value in al 7 ?
  140.             je      mdabase             ; if 7 then its monochrome
  141.             mov     ax,0b800h           ; if not then use CGA for base address
  142.             jmp     SHORT assign        ; goto assign: label
  143. mdabase:                                ; label: where MDA address is put in AX
  144.             mov     ax,0b000h           ; MDA adapter
  145. assign:                                 ; label: where extra seg is assigned
  146.             mov     es,ax               ; point to start of video buffer
  147.             lds     si,dword ptr strg   ; load seg & off for large data models
  148.             inc     si                  ; jump past the length byte
  149.             add     si,bx               ; add the string source offset to SI
  150.             mov     bl,byte ptr color   ; color. get the attribute value
  151.             mov     cx,word ptr col     ; col  . column address
  152.             mov     ax,word ptr row     ; row  . row address
  153.             mov     dx,160              ; bytes per line in CGA
  154.             mul     dx                  ; 160 * row number
  155.             add     ax,cx               ; add column number to offset in CGA buffer
  156.             add     ax,cx               ; add column number to offset in CGA: again
  157.             mov     di,ax               ; put address in CGA into DI
  158.             mov     cx,[strlen]         ; count of chars to write
  159.             cmp     cx,0000h            ; is CX set to zero
  160.             je      gclrchar            ; jump to gclrchar: if CX is zero (there are only chars to clear. none to write)
  161.             mov     ax,word ptr maxchars; maxchars.  get the maximum number of chars to write parameter
  162.             cmp     cx,ax               ; compare string length with maxchars (max allowed chars to write)
  163.             jg      toolong             ; make the string length shorter (it exceeds the max)
  164.             jmp     SHORT gclrchar      ; jump around the next assignment instruction
  165. toolong:    mov     cx,ax               ; set string length to maxchars
  166. gclrchar:   mov     dx,word ptr clrchar ; clrchar. get the number of chars to clear (parameter)
  167.             sub     dx,cx               ; subtract chars to write from clrchar (causes extra work in rare cases)
  168.             cmp     dx,1                ; compare the difference with one
  169.             jl      tooshort            ; if DX is less than one goto tooshort:
  170.             jmp     SHORT alright       ; else goto alright:
  171. tooshort:   mov     dx,0000h            ; set DX to zero (there are no chars to clear)
  172. alright:    mov     [toclear],dx        ; set toclear to the value of DX
  173. oklength:   mov     ah,bl               ; put in an attribute byte in AH (one time !)
  174.             cmp     cx,0000h            ; compare CX to zero. if (cx == 0) goto mdaclear:
  175.             je      mdaclear            ; goto mdaclear: (if cx == 0)
  176. monotop:
  177.             lodsb                       ; get one character put in AL
  178.             stosw                       ; move the word NOW! into the CRT
  179.             loop    monotop             ; bottom of loop
  180. mdaclear:   mov     cx,[toclear]        ; length of field to clear
  181.             cmp     cx,1                ; compare toclear to one
  182.             jl      endfast             ; no spaces need clearing so EXIT
  183.             mov     al,20h              ; put a space char into AL
  184.             rep     stosw               ; zing em all now! (clear the rest of the field)
  185. endfast:                                ; end of effective code
  186.             pop     ds
  187.             ret
  188. snowwrite endp
  189. ;***********************************************************************
  190. ;
  191. ;  SNOWPUTC.ASM  write a char(s) to the textmode screen
  192. ;                no 'snow' checking is done
  193. ;
  194. ; prototype: void far snowputc(int col, int row, char color, char outch, int numb);
  195. ;
  196.         PUBLIC snowputc
  197. snowputc proc    near col: WORD, row: WORD, color: BYTE, outch: BYTE, numb: WORD
  198.         cld                         ; clear direction flag
  199.         sub     ax,ax               ; zero out AX
  200.         mov     es,ax               ; put zero in for extra segment
  201.         mov     al,es:[0449h]       ; offset of 449h is needed
  202.         cmp     al,7                ; is value in al 7 ?
  203.         je      short mdabasepc     ; if 7 then its monochrome
  204.         mov     ax,0b800h           ; if not then use CGA for base address
  205.         jmp     short assignpc      ; goto assign: label
  206. mdabasepc:                          ; label: where MDA address is put in AX
  207.         mov     ax,0b000h           ; MDA adapter
  208. assignpc:                           ; label: where extra seg is assigned
  209.         mov     es,ax               ; point to address in video buffer
  210.         mov     bl,byte ptr outch   ; get the character
  211.         mov     bh, byte ptr color  ; get the attribute
  212.         mov     cx,col              ; column address
  213.         mov     ax,row              ; row address
  214.         mov     dx,160              ; bytes per line in CGA
  215.         mul     dx                  ; 160 * row number
  216.         add     ax,cx               ; add column number to offset in CGA buffer
  217.         add     ax,cx               ; add column number to offset in CGA: again
  218.         mov     di,ax               ; put address in CGA into DI
  219.         mov     cx,numb             ; get the count of chars to write
  220.         mov     ax,bx               ; put in an attribute byte in AX (one time !)
  221.         rep     stosw               ; move the number of char+atribb pairs
  222.         ret
  223. snowputc       ENDP
  224.  
  225. ; prototype: void near puts(char *strg);
  226. ; purpose:   emulate the Turbo C puts() function (text output (slow) in any video mode }
  227. ;            *strg is the string to output to STDOUT
  228. ;
  229.         PUBLIC puts
  230. ;***********************************************************************
  231. puts    proc   near strg: DWORD
  232.          push   ds
  233.          cld
  234.          lds    si,dword ptr strg;      ; load the pointer
  235.          lodsb                          ; load length byte inc pointer
  236.          mov    cx,ax                   ; copy length
  237.          mov    ch,0                    ; max output is 255 bytes
  238.          mov    dx,si                   ; PASS ptr in DS:DX
  239.          mov    bx,1;                   ; STDOUT
  240.          mov    ah,40h;                 ; DOS write file
  241.          int    21h                     ; call DOS
  242.          pop    ds
  243.          ret
  244. puts    ENDP
  245. ;***********************************************************************
  246.  
  247.  
  248.         END
  249.